<?php 
namespace app\admin\service;


use app\admin\model\Prop;

/**
 * 道具配置管理-服务类
 * @author 小树林
 * @since: 2023/12/19
 * Class PropService
 * @package app\admin\service
 */
class PropService extends BaseService
{
    /**
     * 构造函数
     * LevelService constructor.
     */
    public function __construct()
    {
        $this->model = new Prop();
    }
	
	/**
     * 获取数据列表
     * @return array
     * @since 2023/12/19
     * @author 小树林
     */
    public function getList()
    {
        $param = request()->param();

        //是否为远程搜索查询
        $is_query = $param['_is_query'] ?? '';
        if(!empty($is_query)){
            return parent::query($param);
        }
        // 查询条件
        $map = [];
	    // 名称
        $name = isset($param['name']) ? trim($param['name']) : '';
        if ($name) {
            $map[] = ['name', 'like', "%{$name}%"];
        }
	    // 有效标识
        $mark = isset($param['mark']) ? (int)$param['mark'] : 0;
        if ($mark) {
            $map[] = ['mark', '=', $mark];
        }
        $field = '*';
        $with = [];
        $sort = '';
        $res = parent::getList($map,$field,$with,$sort); // TODO: Change the autogenerated stub
        if($res['count'] != 0){
            foreach($res['data'] as $k=>$v){
                $res['data'][$k]['img'] = [];
                $res['data'][$k]['img'][] = get_image_url($v['img']);
            }
        }
        return $res;
    }

    public function edit()
    {
        // 参数
        $data = request()->param();

        // 头像处理
        $avatar = getter($data, 'img');
        if (!empty($avatar)) {
            if (strpos($avatar, "temp") !== false) {
                $data['img'] = save_image($avatar, 'prop');
            } else {
                $data['img'] = str_replace(IMG_URL, "", $avatar);
            }
        }

        return parent::edit($data); // TODO: Change the autogenerated stub
    }


                                                    
}